package com.shanshui.test;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private MenuAdapter mMenuAdapter;
    private List<MenuBean> mMenuBeans;
    private int[] ids = new int[]{0, 1, 2};
    private String[] names = new String[]{"RecyclerViewActivity","InputActivity","imagetest"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        LittleEndianDataOutputStream
        mMenuBeans = new ArrayList<>();
        for (int i = 0; i < ids.length; i++) {
            MenuBean menuBean = new MenuBean();
            menuBean.id = ids[i];
            menuBean.name = names[i];
            mMenuBeans.add(menuBean);
        }
        mMenuAdapter = new MenuAdapter(mMenuBeans);
        RecyclerView recyclerView = findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(mMenuAdapter);
        // 先注册需要点击的子控件id（注意，请不要写在convert方法里）
        mMenuAdapter.addChildClickViewIds(R.id.button);
        // 设置子控件点击监听
        mMenuAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
                switch (position) {
                    case 0:
                        startActivity(new Intent(MainActivity.this, RecyclerViewActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(MainActivity.this, InputActivity3.class));
                        break;
                    default:
                        break;
                }
            }
        });
    }
}